import { View } from "../../../mvc/core/View";
import { LayerManager } from "../../manager/LayerManager";
import { UIIconEvent } from "./UIIconEvent";
import { TweenMax } from "../../../../com/greensock/TweenMax";
import { Vector } from "../../../../__AS3__/vec/Vector";
type int = number;
//class UiHintIconView
    
    export  class UiHintIconView extends View
    {
        constructor()
        {
            super();
            this.layer = LayerManager.uiLayer;
            this._vecHintIcon = new Vector.<View>();
            this.show();
            return;
        }

        public removeHintIconByName(arg1: string): void
        {
            return;
        }

        public removeHintIcon(arg1: View): void
        {
            if (this._vecHintIcon.indexOf(arg1) >= 0) 
            {
                this._vecHintIcon.splice(this._vecHintIcon.indexOf(arg1), 1);
                this.draw("remove");
            }
            return;
        }

        public addHintIcon(arg1: View, arg2: Boolean=true): void
        {
            if (this._vecHintIcon.indexOf(arg1) < 0) 
            {
                arg1.addEventListener(UIIconEvent.RemoveIcon, this.removeHandler);
                this._vecHintIcon.push(arg1);
                this.draw("add", arg2);
            }
            return;
        }

        /* internal  */removeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=arg1.target as View;
            loc1.removeEventListener(UIIconEvent.RemoveIcon, this.removeHandler);
            this.removeHintIcon(loc1);
            return;
        }

        /* internal  */draw(arg1: string, arg2: Boolean=true): void
        {
            var loc1=0;
            var loc2=null;
            this.clear();
            if (arg1 != "add") 
            {
                if (arg1 == "remove") 
                {
                    loc1 = 0;
                    while (loc1 < this._vecHintIcon.length) 
                    {
                        (loc2 = this._vecHintIcon[loc1] as View).x = (loc1 - 1) * (this._iconSize + this._gap);
                        this.addChild(loc2);
                        ++loc1;
                    }
                }
            }
            else 
            {
                loc1 = 0;
                while (loc1 < this._vecHintIcon.length) 
                {
                    loc2 = this._vecHintIcon[loc1] as View;
                    if (loc1 != (this._vecHintIcon.length - 1)) 
                    {
                        loc2.x = (loc1 - 1) * (this._iconSize + this._gap);
                        this.addChild(loc2);
                    }
                    else 
                    {
                        loc2.x = (loc1 - 1) * (this._iconSize + this._gap) + 100;
                        this.addChild(loc2);
                        if (arg2) 
                        {
                            this._tweenIn = TweenMax.to(loc2, 1, {"alpha": 1, "x":(loc1 - 1) * (this._iconSize + this._gap)});
                        }
                        else 
                        {
                            loc2.x = (loc1 - 1) * (this._iconSize + this._gap);
                        }
                    }
                    ++loc1;
                }
            }
            return;
        }

        public UiHintIconView.get vecHintIcon(): Vector.<View>
        {
            return this._vecHintIcon;
        }

        /* internal  */clear(): void
        {
            var loc1=this.numChildren;
            var loc2;
            --loc2;
            while (loc2 >= 0) 
            {
                this.removeChildAt(loc2);
                --loc2;
            }
            return;
        }

        public static get instance(): UiHintIconView
        {
            if (!UiHintIconView._instance) 
            {
                UiHintIconView._instance = new UiHintIconView();
            }
            return UiHintIconView._instance;
        }

        /* internal */ /* var */_vecHintIcon: Vector.<View>;

        /* internal */ /* var */_gap: number=12;

        /* internal */ /* var */_tweenIn: TweenMax;

        protected /* var */_iconSize: int=25;

        /* internal */ static /* var */_instance: UiHintIconView;
    }
